package com.cheyun.netsalev3.view.choosecity


import android.os.Bundle
import android.util.Log
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProviders
import com.cheyun.netsalev3.R
import com.cheyun.netsalev3.adapter.MyAdapter
import com.cheyun.netsalev3.databinding.FragmentChooseCityFragment2Binding
import com.cheyun.netsalev3.utils.BaseFragment
import com.cheyun.netsalev3.viewmodel.ChooseCityActivityViewModel

class ChooseCityFragment2 : BaseFragment<FragmentChooseCityFragment2Binding>() {
    override fun initContentView(): Int {
        return R.layout.fragment_choose_city_fragment2
    }

    override fun initViewModel(): ViewModel? {
        this?.activity?.apply {
            return ViewModelProviders.of(this).get(ChooseCityActivityViewModel::class.java)
        }
        return null
    }

    lateinit var adapter: MyAdapter
    override fun initView() {
        adapter = MyAdapter(R.layout.city_iytem2, binding.viewModel)
        binding.recyclerView.adapter = adapter

    }

    override fun initData() {
        if (pos == "1") {
            binding.viewModel?.citylist?.observe(this, Observer {
                adapter.submitList(it)
            })
        } else {
            binding.viewModel?.qulist?.observe(this, Observer {
                adapter.submitList(it)
            })
        }
    }
    override fun lazyInit() {
        Log.i(TAG,"override lazyinit")
    }

    companion object {
        @JvmStatic
        fun newInstance(pos: String) =
                ChooseCityFragment2().apply {
                    arguments = Bundle().apply {
                        putString("pos", pos)
                    }
                }
    }

    private var pos: String = ""

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            pos = it.getString("pos")
        }
    }

}
